package com.wizz.trade.information.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wizz.trade.information.dto.page.StofPageDto;
import com.wizz.trade.information.entity.Stof;
import com.wizz.trade.information.mapper.StofMapper;
import com.wizz.trade.information.service.StofService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wizz.trade.common.PageVo;
import com.wizz.trade.util.PageUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 仓储费表 服务实现类
 * </p>
 *
 * @author fyftless
 * @since 2023-04-02 04:26:06
 */
@Service
public class StofServiceImpl extends ServiceImpl<StofMapper, Stof> implements StofService {

    @Resource
    private StofMapper stofMapper;
    @Override
    public void addStof(Stof stof) {
        stofMapper.insert(stof);
    }

    @Override
    public void updateStof(Stof stof) {
        stofMapper.updateById(stof);
    }

    @Override
    public void deleteStof(Integer id) {
        stofMapper.deleteById(id);
    }

    @Override
    public PageVo<Stof> getPage(StofPageDto stofPageDto) {
        LambdaQueryWrapper<Stof> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(!Objects.isNull(stofPageDto.getSvar()),Stof::getSvar,stofPageDto.getSvar());
        IPage<Stof> page = stofMapper.selectPage(PageUtil.initPage(stofPageDto), queryWrapper);
        return new PageVo<>(page);
    }

    @Override
    public List<Stof> getAll() {
        return stofMapper.selectList(null);
    }

}
